﻿using System;
using System.Windows.Forms;

namespace TAProject.UI.Order
{
    public partial class FormGroupAdd : FormTemplate
    {
        private readonly Form _parentForm;

        public string Surname { private set; get; }
        public string GName { private set; get; }
        public string FName { private set; get; }
        public bool IsChild { private set; get; }

        public bool Complete { set; get; }

        public FormGroupAdd(Form parentForm, string clientSurname) : base(parentForm)
        {
            InitializeComponent();

            _parentForm = parentForm;
            _parentForm.Enabled = false;

            textBoxSurname.Text = clientSurname;
            
        }

        public FormGroupAdd(Form parentForm, string surname, string name, string fName, bool isChild)
            :this(parentForm, surname)
        {
            textBoxName.Text = name;
            textBoxFatherName.Text = fName;
            checkBoxIsChild.Checked = isChild;
        }

        private void ButtonSubmitClick(object sender, EventArgs e)
        {
            if (CheckFields())
            {
                Surname = textBoxSurname.Text;
                GName = textBoxName.Text;
                FName = textBoxFatherName.Text;
                IsChild = checkBoxIsChild.Checked;
                Complete = true;
                FormClose();
            }
        }

        private void ButtonCancelClick(object sender, EventArgs e)
        {
            Complete = false;
            FormClose();
        }

        private void FormClose()
        {
            _parentForm.Enabled = true;
            Close();
        }

        private bool CheckFields()
        {
            if (string.IsNullOrEmpty(textBoxSurname.Text) ||
                string.IsNullOrEmpty(textBoxName.Text) ||
                string.IsNullOrEmpty(textBoxFatherName.Text))
            {
                MessageBox.Show("Не все поля заполнены!");
                return false;
            }
            return true;
        }
    }
}